<?php

class Authentication extends CI_Controller{

	function __construct(){
		parent::__construct();
		$this->user_authentication->validation('home', 'user_id');
	}
	
	function do_signout(){
		$this->session->sess_destroy();
		redirect('home');
	}
	
	function do_login(){
		$this->form_validation->set_rules('user_name_login', 'Username', 'required');
		$this->form_validation->set_rules('user_password_login', 'Password', 'required');
	
		if ($this->form_validation->run() == false){
			$this->load->view('v_login', $this->value);
		}else{
			$user_name = $_REQUEST['user_name_login'];
			$user_password = $_REQUEST['user_password_login'];
			$this->load->model('m_user');
			$user = $this->m_user->get_user($user_name,$user_password);
			if($user->num_rows()>0){
				$member = $user->result_array();
				$this->session->set_userdata($member[0]);
				redirect('dashboard/main');
			}else{
				show_error("Username atau password salah");
			}
		}
	}
}
?>